let form = layui.form;

form.verify({ // 指定规则名和对应的验证规则
    nickname: [ // 昵称
        /^[\u4E00-\u9FA5]+$/,
        '昵称只能是中文'
    ],
})


axios.get('http://api-breakingnews-web.itheima.net/my/userinfo', {
    headers: {
        Authorization: localStorage.getItem('token')
    }
}).then(function (test) {
    if (test.data.status === 0) {
        let {email, id, nickname, user_pic, username} = test.data.data

        $('input[name=username]').val(username)
        $('input[name=nickname]').val(nickname)
        $('input[name=email]').val(email)
        $('input[type=hidden]').val(id)
    }
})

$('form').on('submit', function (e) {
    e.preventDefault()
    let data = $('form').serialize()
    console.log(data)
    axios.post('http://api-breakingnews-web.itheima.net/my/userinfo', data, {
        headers: {
            Authorization: localStorage.getItem('token')
        }
    }).then(function (test) {
        console.log(test)
        if (test.data.status === 0) {
            layer.msg(test.data.message)

            window.parent._getuser()
        } else {

        }
    })
})




